{*
* 2007-2011 PrestaShop 
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <contact@prestashop.com>
*  @copyright  2007-2011 PrestaShop SA
*  @version  Release: $Revision: 7920 $
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*}

<div id="idTab5">
<script type="text/javascript" src="{$module_dir}js/jquery.rating.pack.js"></script>
<script type="text/javascript">
	$(function(){literal}{{/literal} $('input[@type=radio].star').rating(); {literal}}{/literal});
	$(function(){literal}{{/literal}
		$('.auto-submit-star').rating({literal}{{/literal}
			callback: function(value, link){literal}{{/literal}
			{literal}}{/literal}
		{literal}}{/literal});
	{literal}}{/literal});
	
	//close  comment form
	function closeCommentForm(){ldelim}
		$('#sendComment').slideUp('fast');
		$('input#addCommentButton').fadeIn('slow');
	{rdelim}
</script>
<script language="javascript" type="text/javascript">
	/* no longer needed
	function limitText(limitField, limitCount, limitNum) {
		if (limitField.value.length > limitNum) {
			limitField.value = limitField.value.substring(0, limitNum);
		} else {
			limitCount.value = limitNum - limitField.value.length;
		}
	}
	*/
	
	function checkRequiredFieldsError()
	{
		var requiredFieldNullMsg;
	
		{if $allow_guests == true && $cookie->isLogged() == false}
			var customer_name = document.getElementById('customer_name').value;
			if (customer_name == "")
			{
				requiredFieldNullMsg = "{l s='Please fill in your name.' mod='productcomments'}";
				alert(requiredFieldNullMsg);
				return false;
			}
		{/if}
		
		var content = document.getElementById('content').value;
		if (content == "")
		{
			requiredFieldNullMsg = "{l s='Comment text is required.' mod='productcomments'}";
			alert(requiredFieldNullMsg);
			return false;
		}
	}
</script>
{if $comments}
	{if $criterions|@count > 0}
		<!--table style="margin-bottom: 10px;">
			<tr><td style="padding:0 10px 0 0;font-size:12px;font-weight:bold;color:#777;text-transform:uppercase;">{l s='Average rating:' mod='productcomments'}</td>
			<td>{section loop={$averageTotal|round + 1} step=1 start=1 name=average}
				<input class="auto-submit-star" disabled="disabled" type="radio" name="comment_average" value="{$averageTotal|round}" {if $averageTotal|round neq 0 and $smarty.section.average.index eq $averageTotal|round}checked="checked"{/if} />
			{/section}
			</td>
			</tr>
		</table-->
		<!--div style="float: left">
			{l s='Average' mod='productcomments'}:<br />
			{section loop=6 step=1 start=1 name=average}
				<input class="auto-submit-star" disabled="disabled" type="radio" name="average" {if $averageTotal|round neq 0 and $smarty.section.average.index eq $averageTotal|round}checked="checked"{/if} />
			{/section}
		</div-->
		<!--table style="margin-bottom: 10px;">
			{foreach from=$criterions item=c}
			<tr style="margin-bottom: 10px;">
				<td style="padding:0 10px 0 0;font-size:12px;color:#777;text-transform:uppercase;">{$c.name|escape:'html':'UTF-8'}</td>
				<td>
					{section loop=6 step=1 start=1 name=average}
						<input class="auto-submit-star" disabled="disabled" type="radio" name="{$c.name|escape:'html':'UTF-8'}_{$smarty.section.average.index}" value="{$smarty.section.average.index}" {if isset($averages[$c.id_product_comment_criterion]) AND $averages[$c.id_product_comment_criterion]|round neq 0 AND $smarty.section.average.index eq $averages[$c.id_product_comment_criterion]|round}checked="checked"{/if} />
					{/section}
				</td>
			</tr>
			{/foreach}
		</table-->
		<!--div style="float: left; margin-left: 40px; width: 400px">
		{foreach from=$criterions item=c}
			<div style="float: left; margin-left: 20px; margin-bottom: 10px;">
			{$c.name|escape:'html':'UTF-8'}<br />
			{section loop=6 step=1 start=1 name=average}
				<input class="auto-submit-star" disabled="disabled" type="radio" name="{$c.name|escape:'html':'UTF-8'}_{$smarty.section.average.index}" value="{$smarty.section.average.index}" {if isset($averages[$c.id_product_comment_criterion]) AND $averages[$c.id_product_comment_criterion]|round neq 0 AND $smarty.section.average.index eq $averages[$c.id_product_comment_criterion]|round}checked="checked"{/if} />
			{/section}
			</div>
		{/foreach}
		</div-->
	{/if}
	<div class="clear table_block">
		<table class="std" style="width: 100%">
			<thead>
				<tr>
					<th class="first_item" style="width:80px;">{l s='From' mod='productcomments'}</th>
					<th class="item" style="width:110px;">{l s='Rating' mod='productcomments'}</th>
					<th class="item">{l s='Comment' mod='productcomments'}</th>
				</tr>
			</thead>
			<tbody>
			{foreach from=$comments item=comment}
				{if $comment.content}
				<tr>
					<td style="vertical-align:top">
						{dateFormat date=$comment.date_add|escape:'html':'UTF-8' full=0}
						{$comment.customer_name|escape:'html':'UTF-8'}.
					</td>
					<td style="vertical-align:top">
						{if $comment.grade}
							{section loop={$comment.grade|round + 1} step=1 start=1 name=average}
								<input class="auto-submit-star" disabled="disabled" type="radio" name="{$comment.name|escape:'html':'UTF-8'}_{dateFormat date=$comment.date_add|escape:'html':'UTF-8' full=1}" value="{l s='Rating:' mod='productcomments'} {$comment.grade|round}" {if $comment.grade|round neq 0 and $smarty.section.average.index eq $comment.grade|round}checked="checked"{/if}/>
							{/section}
						{else}
							&mdash;
						{/if}
					</td>
					<td style="vertical-align: top">
						{$comment.content|escape:'html':'UTF-8'|nl2br}
					</td>
				</tr>
				{/if}
			{/foreach}
			</tbody>
		</table>
	</div>
{else}
	<p class="align_center">{l s='No customer comments for the moment.' mod='productcomments'}</p>
{/if}

{if $too_early == true}
	<p class="align_center">{l s='You should wait' mod='productcomments'} {$delay} {l s='second(s) before posting a new comment' mod='productcomments'}</p>
{elseif $cookie->isLogged() == true || $allow_guests == true}
<p class="align_center"><input style="margin:auto;" class="button_large" type="button" id="addCommentButton" value="{l s='Add a comment' mod='productcomments'}" onclick="$('#sendComment').slideDown('slow');$(this).slideUp('slow');" /></p>
<form action="{$action_url}" method="post" class="std" id="sendComment" style="display:none;" onsubmit="return checkRequiredFieldsError();">
	<fieldset>
		<p class="align_right"><a href="javascript:closeCommentForm()">X</a></p>
		<p class="bold">{l s='Add a comment' mod='productcomments'}</p>
		{if $criterions|@count > 0}
		<table style="margin-top: 10px; margin-bottom: 10px;">
		{section loop=$criterions name=i start=0 step=1}
		<tr>
			<!--td>&nbsp;&nbsp;&nbsp;&nbsp;</td-->
			<td style="font-size:12px;color:#777;text-transform:uppercase;"><p class="required select">
				<input type="hidden" name="id_product_comment_criterion_{$smarty.section.i.iteration}" value="{$criterions[i].id_product_comment_criterion|intval}" />
				<sup>*</sup> {$criterions[i].name|escape:'html':'UTF-8'}</p>
			</td>
			<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
			<td style="padding:4px 0 0 0;">
			<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" id="{$smarty.section.i.iteration}_grade" value="1" />
			<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="2" />
			<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="3" checked="checked" />
			<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="4" />
			<input class="star" type="radio" name="{$smarty.section.i.iteration}_grade" value="5" />
			</td>
		</tr>
		{/section}
		</table>
		{/if}
		{if $allow_guests == true && $cookie->isLogged() == false}<p class="required required_desc"><label for="customer_name"><sup>*</sup> {l s='Your name:' mod='productcomments'}</label><input type="text" name="customer_name" id="customer_name" /></p>{/if}
		<!--p><label for="comment_title">{l s='Title:' mod='productcomments'}</label><input type="text" name="title" id="comment_title" /></p-->
		<p class="required required_desc"><label for="content"><sup>*</sup> {l s='Comment:' mod='productcomments'} ({l s='max. characters: 500' mod='productcomments'}<label id="nbchars" style="display:inline"></label>)</label><textarea cols="46" rows="5" maxlength="500" name="content" id="content" onKeyUp="var length = document.getElementById('content').value.length; if (length > 500) length = '500+'; document.getElementById('nbchars').innerHTML = ' [' + length + ']';"></textarea></p>
		<p class="required required_desc">
			<span><sup>*</sup> {l s='Required field' mod='productcomments'}</span>
		</p>
		<p class="submit">
			<input class="button" name="submitMessage" value="{l s='Send' mod='productcomments'}" type="submit" />
		</p>
	</fieldset>
</form>
{else}
	<p class="align_center">{l s='Only registered users can post a new comment.' mod='productcomments'}</p>
	<p class="align_center"><a href="{$link->getPageLink("my-account.php")}" style="margin:auto;" class="button">{l s='Sign in' mod='productcomments'}</a></p>
{/if}
</div>